Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module for writing unit tests #121

Merged
merged 14 commits into from
Feb 26, 2025
Merged

Add module for writing unit tests #121

merged 14 commits into from
Feb 26, 2025

Conversation

podocarp
Copy link
Member

@podocarp podocarp commented Dec 14, 2021

Description

Usually testing of programs in source academy is done by commenting and uncommenting code. This is a great big hassle. I have also noticed that students usually only run a single test at a time and comment/uncomment
every single line manually, which makes it even slower. Thus it would be great if we could introduce proper unit testing into Source.

This module adds a few function for writing tests and asserts, as well as a new tab to report on test statuses.
image

I have generally tried to keep to a style similar to jest.

Future extensions:

  • Compare runes, sound, etc.
  • Style the tab a bit nicer

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added unit tests, as well as manual testing.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@podocarp podocarp self-assigned this Dec 14, 2021
@podocarp podocarp added the Enhancement [Category] New feature request label Dec 14, 2021
Copy link
Contributor

@Anonymxtrix Anonymxtrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! I think that this test module that you have written will definitely be a hit among the source academy cadets! Too bad this wasn't yet implemented when I was taking 1101s haha.

The comments I added are generally my opinion (pls don't take any offence) and feel free to contact me if you wish to discuss or argue against any of the points I wrote so that we can learn together as well! :)

@martin-henz
Copy link
Member

This PR is still marked as "draft". @podocarp: Or is it ready for final review?

@podocarp podocarp marked this pull request as ready for review March 2, 2022 02:20
@podocarp
Copy link
Member Author

podocarp commented Mar 2, 2022

Have not written docs yet, but hope someone can look at the code first.

@RichDom2185 RichDom2185 requested review from RichDom2185, leeyi45 and martin-henz and removed request for MarcusTXK April 8, 2024 18:01
@leeyi45
Copy link
Contributor

leeyi45 commented Feb 24, 2025

I've looked through this PR, and as it stands it's basically done. There is an issue though: I don't see any way to have more than describe block per program.

Given that Source now supports multiple files and multiple calls to display results on tabs, if we don't mind removing describe I think I can get this to a working state.

@RichDom2185
Copy link
Member

I've looked through this PR, and as it stands it's basically done. There is an issue though: I don't see any way to have more than describe block per program.

Given that Source now supports multiple files and multiple calls to display results on tabs, if we don't mind removing describe I think I can get this to a working state.

I think the vast majority of use cases still involve single-file programs, so as long as it works for a single file, I think we can safely merge it first

@RichDom2185 RichDom2185 changed the title [WIP] Add module for writing unit tests Add module for writing unit tests Feb 26, 2025
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM based on @leeyi45's comment above, thanks!

@RichDom2185 RichDom2185 enabled auto-merge (squash) February 26, 2025 00:44
@RichDom2185 RichDom2185 merged commit b222161 into master Feb 26, 2025
3 checks passed
@RichDom2185 RichDom2185 deleted the jxd-unittest branch February 26, 2025 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement [Category] New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants